/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import main.WinkelApplication;

/**
 *
 * @author loki
 * 
 * Keeps a list of all windows previously viewed.
 */
public class WindowsViewed {
    private List<JPanel> viewed;
    //The position of the current window in the list.
    private int currentWindow;
    
    public WindowsViewed(JPanel firstWindow) {
        viewed = new ArrayList();
        viewed.add(firstWindow);
        WinkelApplication.getInstance().showPanel(firstWindow);
        currentWindow = 0;
    }
    
    //Gets the window previously viewed.
    public void previous() {
        //Its not the first window in the list
        if(currentWindow > 0) {
            WinkelApplication.getInstance().showPanel(viewed.get(currentWindow - 1));
            currentWindow--;
        }
    }
    
    //Go one window forward.
    public void next() {
        //Its not the last object of the list.
        if(currentWindow < viewed.size() - 1) {
            WinkelApplication.getInstance().showPanel(viewed.get(currentWindow + 1));
            currentWindow++;
        }
    }
    
    //Add a new window
    public void newWindow(JPanel nextWindow) {
        //Remove all objects from the list from the back to the currentWindow
        for(int back = viewed.size() - 1;back > currentWindow; back--) {
            viewed.remove(back);
        }
        viewed.add(nextWindow);
        WinkelApplication.getInstance().showPanel(nextWindow);
        
        currentWindow++;
    }    
}
